# -*- coding: utf8 -*-
'''
    1.1.3 复制和粘贴图像区域
'''

import os
from PIL import Image

infile = 'img/haizei.jpg'
outfile1 = os.path.splitext(infile)[0] + '1.1.3-1.jpg'
outfile2 = os.path.splitext(infile)[0] + '1.1.3-2.jpg'
pil_im = Image.open(infile)
# 复制区域是一个矩形，左上角坐标，右下角坐标
# 左，上，右，下
box = (78, 92, 78+75, 92+73)
region = pil_im.crop(box)
region.save(outfile1)
# 将旋转后的复制图片再替换原来的
region = region.transpose(Image.ROTATE_180)
pil_im.paste(region, box)
pil_im.save(outfile2)
